package com.solid.api.controller;

import com.solid.rabbitmq.producer.DelayProducer;
import com.solid.rabbitmq.producer.MsgProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Package:
 * @Description:
 * @Author: Mr.z
 * @CreatDate: 2020/06/02
 */
@RestController
@RequestMapping("/rabbit/v1.0/test")
public class RabbitController {
    @Autowired
    private MsgProducer msgProducer;
    @Autowired
    private DelayProducer delayProducer;

    @GetMapping(value = "/sendFanout")
    public void sendMsg() {
        msgProducer.send2FanoutTestQueue("this is a test fanout message!");
    }

    @GetMapping(value = "/sendDirect")
    public void sendDirectMsg() {
        msgProducer.send2DirectTestQueue("this is a test direct message!");
    }

    @GetMapping(value = "/sendDirectA")
    public void sendTopicAMsg() {
        msgProducer.send2TopicTestAQueue("this is a test topic aaa message!");
    }

    @GetMapping(value = "/sendTopicB")
    public void sendTopicBMsg() {
        msgProducer.send2TopicTestBQueue("this is a test topic bbb message!");
    }

    @GetMapping("/fanout")
    public void fanout() {
        for (int i = 0; i < 5; i++) {
            msgProducer.producerFanout("发布订阅模式下的第" + i + "条信息");
        }
    }

    @GetMapping("/direct")
    public void direct() {
        for (int i = 0; i < 5; i++) {
            msgProducer.producerDirect("路由模式下的第" + i + "条信息");
        }
    }


    @GetMapping("/vipDelay/{time}")
    public void vipDelay(@PathVariable("time") Long time) {
        delayProducer.sendVipDelay(1L, time);
    }
}
